home *** CD-ROM | disk | FTP | other *** search
- /* copyc.c - copy a file using read/write */
- #include"stdio.h"
-
- #define NO_FILE (-1)
- #define BUF_SIZE 1024
- #define RD_MODE 0
- #define WR_MODE 0
-
- main(argc,argv)
- int argc ;
- char *argv[] ;
- {
- int in , out ;
- long n ;
- char buffer[BUF_SIZE] ;
- int nr ;
-
- if( argc < 3 )
- { printf(" USAGE - Copy1 input-file output-file \n") ;
- exit (1) ;
- }
-
- in = open( argv[1] , RD_MODE ) ;
- out= creat(argv[2] , WR_MODE ) ;
- if( (in == NO_FILE) || (out == NO_FILE) )
- { printf("Can't open a file") ;
- exit (2) ;
- }
-
- n = 0L ;
- nr = read(in,buffer,BUF_SIZE) ;
- while (nr > 0 )
- { n = n + nr ;
- write (out,buffer,nr) ;
- nr = read(in,buffer,BUF_SIZE) ;
- } ;
- close (in) ;
- close (out);
- printf(" %1d characters copied",n) ;
- }
-
-